﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public static class MaterialPool
{
    private static Dictionary<MaterialRequest, Material> matDictionary;

    static MaterialPool()
    {
        matDictionary = new Dictionary<MaterialRequest, Material>();
    }

    public static Material MatFrom(MaterialRequest req)
    {
        if (!matDictionary.TryGetValue(req, out var value))
        {
            value = new Material(req.shader);

            if (req.mainTex != null)
            {
                Material material = value;
                material.name = material.name + "_" + req.mainTex.name;
                value.mainTexture = req.mainTex;
            }
            value.color = req.color;
            //下面就是一些Shader参数的赋值启用了

        }
        return value;
    }

    //public static Material MatFrom(Texture2D mainTex, Shader shader, Color color)
    //{


    //}

}

